package com.gitee.wsl.security.signature

import com.gitee.wsl.ext.array.toByteString
import kotlinx.io.bytestring.ByteString

interface SignatureAlgorithm {
    fun sign(message: ByteArray, privateKey: ByteArray): ByteArray

    /** Returns true if [signature] with [message], can be verified with [publicKey]. */
    fun verify(message: ByteArray, signature: ByteArray, publicKey: ByteArray): Boolean

    companion object
}

fun SignatureAlgorithm.sign(message: ByteString, privateKey: ByteString): ByteString
             = sign(message.toByteArray(), privateKey.toByteArray()).toByteString()

fun SignatureAlgorithm.verify(message: ByteString, signature: ByteString, publicKey: ByteString)
            =verify(message.toByteArray(),signature.toByteArray(), publicKey.toByteArray())

